package com.example.repository.impl;

import com.example.entity.Student;
import com.example.repository.SelfDefineQuery;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

public class StudentRepositoryImpl implements SelfDefineQuery {

    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public List<Student> selfDefineQuery(String name) {
        String jpql = "select s from Student s where s.name = :name";
        Query query = entityManager.createQuery(jpql);
        query.setParameter("name", name);
        return query.getResultList();
    }
}
